/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.stream.IntStream;

/**
 * <p>Project: javaseapp - Stream5
 * <p>Powered by webrx On 2021-08-23 11:52:42
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Stream5 {
    public static void main(String[] args) {
        var is = IntStream.rangeClosed(1, 100);
        //System.out.println(is.sum());

        var sum = is.reduce(0, (a, b) -> a + b);
        System.out.println(sum);

        //求7的阶乘 使用reduce归约
        var ss = IntStream.rangeClosed(1, 7);
        System.out.println(ss.reduce(1, (a, b) -> a * b));

        var s2 = 1;
        for (int i = 1; i <= 7; i++) {
            s2 *= i;
        }
        System.out.println(s2);

        //使用归约求流中数据之和
        var sm3 = IntStream.of(1, 9, 5, 3, 10);
        System.out.println(sm3.reduce((a, b) -> a + b).getAsInt());
    }
}
